<?php
/**
 * Created by PhpStorm.
 * User: Eric
 * Date: 16/5/30
 * Time: PM12:56
 */
System::load_app_class('base','mobileapi','no');
class category extends base
{
    public function __construct()
    {
        parent::__construct();
        $this->db = System::load_sys_class('model');
    }
    //商品分类
    public function shopclass(){
        
        $category = $this->db->GetList("select *  from `@#_category` where `model`= '1' AND `parentid`='0' ");
        
         $info=array("category"=>$category);
          $this->success($info);
    } 

    public function init(){
        $topCategory = $this->db->GetList("SELECT `cateid`,`name`,`info` FROM `@#_category` WHERE `parentid`=0 AND model=1 ORDER BY `order` DESC");
        foreach($topCategory as $key => $value){
            $subCategory = $this->db->GetList("SELECT `cateid`,`name`,`parentid`,`thumb` FROM `@#_category` WHERE `parentid`=".$value['cateid']." AND model=1 order by `order` desc");
            $tmp = unserialize($value['info']);
            $topCategory[$key]['thumb'] = $tmp['thumb'];
            unset( $topCategory[$key]['info']);
            $topCategory[$key]['subCategory'] = $subCategory;
        }
        if($topCategory){
            $this->success($topCategory);
        }else{
            $this->failed($topCategory);
        }

    }
}